package com.yonyou.pmclouds.workstartreport.process;

import com.yonyou.pmclouds.basecom.bp.processor.SingleProcessor;
import com.yonyou.pmclouds.basecom.bp.template.SingleUpdateBpTemplate;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.picture.entity.PictureParamVO;
import com.yonyou.pmclouds.picture.rmiitf.PictureRemoteService;
import com.yonyou.pmclouds.workstartreport.entity.WorkStartCheckVO;
import com.yonyou.pmclouds.workstartreport.entity.WorkStartVO;
import com.yonyou.pmclouds.workstartreport.mapper.WorkStartCheckMapper;

public class WorkStartSingleUpdateProcessor implements SingleProcessor<WorkStartVO> {
    private PictureRemoteService pictureService;
    private WorkStartCheckMapper checkMapper;
    private SingleUpdateBpTemplate singleUpdateBpTemplate;
    public WorkStartSingleUpdateProcessor(WorkStartCheckMapper checkMapper,PictureRemoteService pictureService,SingleUpdateBpTemplate singleUpdateBpTemplate){
        this.checkMapper=checkMapper;
        this.pictureService=pictureService;
        this.singleUpdateBpTemplate=singleUpdateBpTemplate;
    }

    @Override
    public void process(WorkStartVO vo, WorkStartVO orig) throws BusinessException {
        //获取检查项数组
        WorkStartCheckVO[] workStartCheckVOS = vo.getWorkStartCheckVOS();
        //遍历数组
        for (WorkStartCheckVO w:workStartCheckVOS){
            //更新检查项
            singleUpdateBpTemplate.update(w);
            //判断图片是否更改
            if (w.getPictures()!=null){
                //更新图片信息
                pictureService.updateBillPicture(w,new PictureParamVO(vo.getPkWorkstartreport(),vo.getPkProject(),vo.getBillType()));
            }
        }

    }
}
